/*
 * @Author: szx
 * @Date: 2022-05-02 13:39:30
 * @LastEditTime: 2022-05-02 13:41:02
 * @Description:
 * @FilePath: \leetcode\100-199\173\173.js
 */
var BSTIterator = function (root) {
    this.idx = 0;
    this.arr = [];
    inorderTraversal(root, this.arr);
};

BSTIterator.prototype.next = function () {
    return this.arr[this.idx++];
};

BSTIterator.prototype.hasNext = function () {
    return this.idx < this.arr.length;
};

const inorderTraversal = (root, arr) => {
    if (!root) {
        return;
    }
    inorderTraversal(root.left, arr);
    arr.push(root.val);
    inorderTraversal(root.right, arr);
};
